<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<!-- <script type="text/javascript" src="js/socket.io.js"></script> -->
</head>
<body>
<div id="console" class="well"></div>

 <form class="well form-inline" onsubmit="return false;">
         <input id="name" class="input-xlarge" type="text" placeholder="用户名称..."/>
           <input id="msg" class="input-xlarge" type="text" placeholder="发送内容..."/>
            <button type="button" onClick="sendMessage()" class="btn">Send</button>
            <button type="button" onClick="sendDisconnect()" class="btn">Disconnect</button>
  </form>


</body>
</html>
<script type="text/javascript">

	var socket =  io.connect('http://localhost:1180');
	socket.on('connect', function() {
	    output('<span class="connect-msg">Client has connected to the server!</span>');
	});
	
	socket.on('hello', function(data) {
		alert(data.id);
	    output('<span class="username-msg">' + data.id + ':</span> ' + data.name);
	});
	
	socket.on('disconnect', function() {
	    output('<span class="disconnect-msg">The client has disconnected!</span>');
	});
	function sendDisconnect() {
	    socket.disconnect();
	}
	
	function sendMessage() {
	    var userName = $("#name").val()
	    var message = $('#msg').val();
	    $('#msg').val('');
	    socket.emit('testSocket', {id: userName, name: message});
	}
	
	function output(message) {
	    var currentTime = "<span class='time'>" +  new Date() + "</span>";
	    var element = $("<div>" + currentTime + " " + message + "</div>");
	    $('#console').prepend(element);
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
// function connectQuotation(uid, callback) {
//     // 链接行情server
//     socket = io.connect('http://localhost:8089');
//     // 如果用户在web端登陆，那么发送握手请求
//     if (uid) {
//         // 连接上server后
//         socket.on('connect', function() {
//             // 发送握手请求
//             var jsonObject = {
//                 uid : parseInt(uid),
//                 message : "hello"
//             };
//             this.emit('helloevent', jsonObject);

//             this.on('hellopush', function(data, ackServerCallback, arg1) {
//                 // base64转码的数据，可忽视
//                 YUNM.session = {
//                     sessionId : $.base64.atob(data.sessionId),
//                     time : $.base64.atob(data.time)
//                 };
//                 if (ackServerCallback) {
//                     ackServerCallback('server message was delivered to client!');
//                 }
//             });
//         });
//     }



</script>